package com.haste.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author haste
 * mp自动填充配置类
 */
@Component
public class MpAutoFillConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "disabled", () -> 2, Integer.class);
        this.strictInsertFill(metaObject, "sort", () -> 0, Integer.class);
        this.strictInsertFill(metaObject, "operator", () -> "admin", String.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "operator", () -> "admin", String.class);
    }
}
